package com.Init;


import java.io.File;
import android.content.Context;
import android.graphics.Bitmap;
import com.Managers.DirManagerClass;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;


public class ImageDownloaderInit {

    public static void config(Context context, String folder) {

        File cacheDir = new File(DirManagerClass.getSDPath()
                    + DirManagerClass.ThumbsPath + folder);
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(3) // default
        .threadPriority(Thread.NORM_PRIORITY - 2) // default
        .tasksProcessingOrder(QueueProcessingType.FIFO) // default
        .writeDebugLogs().denyCacheImageMultipleSizesInMemory().discCache(new UnlimitedDiscCache(cacheDir, new FileNameGenerator() {

            @Override
            public String generate(String imageUri) {

                String name = DirManagerClass.getPictureNameWE(imageUri);

                return name;
            }
        })) // default

        .build();

        if (ImageLoader.getInstance().isInited())
            ImageLoader.getInstance().destroy();

        ImageLoader.getInstance().init(config);
    }

    public static DisplayImageOptions getOptionsForGrid() {

        return new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).considerExifParams(false).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(Bitmap.Config.RGB_565).build();
    }

    public static DisplayImageOptions getOptionsForList() {

        return new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).considerExifParams(false).bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).build();

    }
}
